﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using LongSCADA_WPF.Helpers;
using LongSCADA_WPF.Message;
using LongSCADA_WPF.Models;
using LongSCADA_WPF.Services;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using Menu = LongSCADA_WPF.Models.Menu;

namespace LongSCADA_WPF.ViewModels
{
    public partial class MainViewModel:ObservableObject
    {
        // 测试日志功能和参数获取
        private readonly ILogger<MainViewModel> _logger; 
        private RootParam _rootParam;

        public UserModelService CurrentUserServicePro { get; }
        public List<Menu> MenuEntities { get; set; } = new List<Menu>();
        public MainViewModel(UserModelService userModelService, ILogger<MainViewModel> logger,IOptionsSnapshot<RootParam> rootParam)
        {
            CurrentUserServicePro = userModelService;
            _logger = logger;
            _rootParam = rootParam.Value;
            InitData();
            
        }

        private void InitData()
        {
            MenuEntities = SqlSugarHelper.Db.Queryable<Menu>().ToList();

            //测试日志功能
           /* _logger.LogInformation("测试日志功能");
            _logger.LogInformation("测试日志功能，参数：{0}", _rootParam.PlcParam.PlcIp);*/
        }

        /// <summary>
        /// 通知 -- 导航栏切换命令
        /// </summary>
        /// <param name="menu"></param>
        [RelayCommand]
        void Navigation(Menu menu)
        {
            WeakReferenceMessenger.Default.Send(menu);
        }

        [RelayCommand]
        void ChangeUser()
        {
            //用户登出消息
            WeakReferenceMessenger.Default.Send(new LogOutMessage(CurrentUserServicePro.CurrentUserModel));
        }
    }
}
